﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace JSTT_DATA_ENTITY.XMLDatas
{
    /// <summary>
    /// Represent DataTypeRule.DF_TableInfo.TableColumns.Column Element  
    /// </summary>
    public class DataRuleTableColumn
    {
        private string _name;
        private string _displayName;
        private string _columnType;
        private int _autoIncrease;
        private int _typeLength;
        private string _columnIsKey;
        private string _itemUnitName;

        public DataRuleTableColumn()
        {
        }

        /// <summary>
        /// DataRuleTableColumn 
        /// </summary>
        /// <param name="name">Column名称</param>
        /// <param name="displayName">Column显示名称</param>
        /// <param name="columnType">Column类型</param>
        /// <param name="typeLength">Column</param>
        /// <param name="autoIncrease">Column自动增长值</param>
        /// <param name="columnIsKey">Column是否为KEY</param>
        public DataRuleTableColumn(string name, string displayName, string columnType,
            int typeLength, int autoIncrease=0, string columnIsKey = "false",string itemUnitName="")
        {
            this._name = name;
            this._displayName = displayName;
            this._columnType = columnType;
            this._typeLength = typeLength;
            this._autoIncrease = autoIncrease;
            this._columnIsKey = columnIsKey;
            this._itemUnitName = itemUnitName;
        }


        /// <summary>
        /// DataTypeRule.DF_TableInfo.TableColumns.Column.Name Attribute 
        /// </summary>
        [XmlAttribute("Name")]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// DataTypeRule.DF_TableInfo.TableColumns.Column.DisplayName Attribute 
        /// </summary>
        [XmlAttribute("DisplayName")]
        public string DisplayName
        {
            get { return _displayName; }
            set { _displayName = value; }
        }

        /// <summary>
        /// DataTypeRule.DF_TableInfo.TableColumns.Column.ColumnType Attribute 
        /// </summary>
        [XmlAttribute("ColumnType")]
        public string ColumnType
        {
            get { return _columnType; }
            set { _columnType = value; }
        }

        /// <summary>
        /// DataTypeRule.DF_TableInfo.TableColumns.Column.TypeLength Attribute 
        /// </summary>
        [XmlAttribute("TypeLength")]
        public int TypeLength
        {
            get { return _typeLength; }
            set { _typeLength = value; }
        }

        /// <summary>
        /// DataTypeRule.DF_TableInfo.TableColumns.Column.AutoIncrease Attribute 
        /// </summary>
        [XmlAttribute("AutoIncrease")]
        public int AutoIncrease
        {
            get { return _autoIncrease; }
            set { _autoIncrease = value; }
        }

        /// <summary>
        /// DataTypeRule.DF_TableInfo.TableColumns.Column.ColumnIsKey Attribute 
        /// </summary>
        [XmlAttribute("ColumnIsKey")]
        public string ColumnIsKey
        {
            get { return _columnIsKey; }
            set { _columnIsKey = value; }
        }

        [XmlAttribute("ItemUnitName")]
        public string ItemUnitName
        {
            get { return _itemUnitName; }
            set { _itemUnitName = value; }
        }
    }

    ///// <summary>
    ///// Represent DataTypeRule.DF_TableInfo.TableColumns Element 
    ///// <TableColumns>
    /////     <ColumnName="ID" DisplayName="" ColumnType="int" AutoIncrease=1>
    /////     <ColumnName="JST_DEVICE_ID" DisplayName="DEVICE ID" ColumnType="int"> 
    ///// </TableColumns> 
    ///// </summary>
    //public class DataRuleTableColumns
    //{
    //    private List<DataRuleTableColumn> dtColumns;

    //    public DataRuleTableColumns()
    //    {
    //        dtColumns = new List<DataRuleTableColumn>();
    //    }

    //    public void AddColumn(DataRuleTableColumn dtc)
    //    {
    //        dtColumns.Add(dtc);
    //    }

    //    public void AddColumn(string name, string displayName, string columnType,
    //        int typeLength, int autoIncrease = 0, bool columnIsKey = false)
    //    {
    //        dtColumns.Add(new DataRuleTableColumn(name,displayName,columnType,typeLength,autoIncrease,columnIsKey));
    //    }

    //    public void ClearColumns()
    //    {
    //        dtColumns.Clear();
    //    }

    //    [XmlArrayItem("Column", typeof (DataRuleTableColumn))]
    //    [XmlArray("TableColumns_OTHERS")]
    //    public DataRuleTableColumn[] TableColumns
    //    {
    //        get
    //        {
    //            return dtColumns.ToArray();
    //        }
    //        set
    //        {
    //            foreach (DataRuleTableColumn dataRuleTableColumn in value)
    //            {
    //                dtColumns.Add(dataRuleTableColumn);
    //            }
    //        }
    //    }
    //}
}
